<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>面试</title>
</head>

<body>
    <!-- IMPORT JS -->
    <script>
        /* 第一题 */
        /* const computed = arr => {
            arr = arr.map((item, index) => {
                return {
                    item,
                    index: index + 2
                };
            });
            arr.sort((a, b) => b.item - a.item);
            return arr.map(obj => {
                return obj.index;
            });
        };
        console.log(computed([4, 2, 3, 1]));//[2,4,3,5] */

        /* 第二题 */
        /* const computed = arr => {
            let len = arr.length,
                result = [],
                middle;
            if (len === 0) return 4;
            middle = len / 2;
            if (len % 2 === 0) {
                // 取中间四个
                result = len <= 4 ? arr.slice() : arr.slice(middle - 2, middle + 2);
            } else {
                // 取中间五个
                result = len <= 5 ? arr.slice() : arr.slice(middle - 2, middle + 3);
            }
            // 求和
            if (result.length === 1) return result[0];
            return result.reduce((x, item) => x + item);
        };
        console.log(computed([1, 2, 3, 4, 5, 6, 7, 8, 9])); */

        /* 第三题：取约数 */
        /*
        const computed = num => {
            num = Math.abs(num);
            let arr = [];
            for (let i = num; i >= 1; i--) {
                if (num % i === 0) arr.push(i);
            }
            if (arr.length > 9) {
                arr = arr.slice(0, 9);
            } else {
                arr = arr.reverse();
            }
            return arr;
        };
        console.log(computed(72)); //[72,36,24,18,12,9,8,6,4]
        */
    </script>
</body>

</html>